/*
 * @lc app=leetcode.cn id=88 lang=javascript
 *
 * [88] 合并两个有序数组
 */

// @lc code=start
/**
 * @param {number[]} nums1
 * @param {number} m
 * @param {number[]} nums2
 * @param {number} n
 * @return {void} Do not return anything, modify nums1 in-place instead.
 */
var merge = function (nums1, m, nums2, n) {
  const res = [];
  let p1 = 0,
    p2 = 0;
  while (p1 < m && p2 < n) {
    if (nums1[p1] >= nums2[p2]) {
      res.push(nums2[p2]);
      p2++;
    } else {
      res.push(nums1[p1]);
      p1++;
    }
  }
  res.push(...nums1.slice(p1, m));
  res.push(...nums2.slice(p2, n));
  res.forEach((val, index) => {
    nums1[index] = val;
  });
};
// @lc code=end
